/*
Jack Morris
11/20/14
Chapter 8
Page 178
Assinment 7
*/

#include <stdio.h>
#define ROWS 5
#define COLUMNS 5

int main(void) {

   int matrix[ROWS][COLUMNS];
   int i;
   int j;
   int row_total = 0;
   int column_total = 0;

   //Get user's input 
   printf("Enter integers for a %d x %d matrix.\n\n", ROWS, COLUMNS);
   for (i = 0; i < ROWS; i++) {
      printf("Enter row %d: ", i + 1);
      for (j = 0; j < COLUMNS; j++) {
         scanf("%d", &matrix[i][j]);
      }
   }

   //Print the calculated row totals 
   printf("\nRow totals: ");
   for (i = 0; i < ROWS; i++) {
      for (j = 0; j < COLUMNS; j++) {
         row_total += matrix[i][j];
      }
      printf("%d ", row_total);
      row_total = 0;
   }

   //Print the calculated column totals
   printf("\nColumn totals: ");
   for (j = 0; j < COLUMNS; j++) {
      for (i = 0; i < ROWS; i++) {
         column_total += matrix[i][j];
      }
      printf("%d ", column_total);
      column_total = 0;
   }

   return 0;
}